
<template>
  <div class="app-header">
    <div class="login">
      <img
        v-if="userStore.logostyletype == 1"
        style="width: 40px; height: 28px"
        :src="userStore.logoimg()"
        alt=""
      />
      <img v-else style="width: 70px; height: 28px" :src="userStore.logoimg()" alt="" />
    </div>
    <div class="header">
      <app-menu />
      <div>
        <app-message />
        <el-popover popper-class="popover_user" placement="bottom" :width="332" trigger="click">
          <template #reference>
            <img
              :src="touxiang"
              style="width: 24px; height: 24px; border-radius: 4px; cursor: pointer"
              alt=""
            />
          </template>
          <div class="popover_user_content">
            <div class="popover_user_bg"></div>
            <div class="popover_user_list">
              <div class="user_popover_user">
                <div class="touxiang">
                  <img :src="touxiang" style="width: 64px; height: 64px; border-radius: 4px" alt="" />
                </div>
                <div class="user_name">{{ userStore.user.user_name }}</div>
                <div class="login_out" @click="userStore.logout()">
                  <img src="@/assets/home/exit.png" style="width: 16px; height: 16px" alt="" />
                  <div style="margin-left: 4px">{{languageJson.user.logOut}}</div>
                </div>
              </div>
              <div class="user_popover_detail">
                <div class="balance">
                  <div class="text1">{{languageJson.user.balance}}</div>
                  <div class="text2">{{userStore.user.subscribe[`${userStore.user.plant_code}:data_limit`] == null ? '--' : userStore.user.subscribe[`${userStore.user.plant_code}:data_limit`].total_number}}</div>
                </div>
                <div class="profit_loss">
                  <div class="text1">{{languageJson.user.todayProfitLoss}}</div>
                  <div class="text2">{{ earningsdata.today_earnings.toFixed(2) }}</div>
                  <div class="text3">{{languageJson.user.yesterdayProfitLoss}} {{ earningsdata.yesterday_earnings.toFixed(2) }}</div>
                </div>
              </div>
              <div class="user_popover_buttons">
                <div class="user_popover_buttons_item">
                  <div style="display: flex">
                    <img src="@/assets/home/accounting.png" style="width: 16px; height: 16px" alt="" />
                  </div>
                  <div style="margin-left: 12px" @click="router.replace('account')">{{languageJson.user.accountHistory}}</div>
                </div>
              </div>
            </div>
          </div>
        </el-popover>
      </div>
    </div>
  </div>
</template>

<script setup>
import touxiang from '@/assets/menu/touxiang.jpg'
import { http } from '@/utils/http'
import { onMounted } from 'vue'
const languageJson = inject('languageJson')
const languageType = inject('languageType')
const userStore = useUserStore()
const router = useRouter()
const handleCommand = command => {
  userStore.logout()
}
const earningsdata = ref({
  today_earnings: 0,
  yesterday_earnings: 0,
})
const sotre = useAppStore()
const { menuIndex, selectMenu } = toRefs(sotre)

const getFirstLetter = str => {
  return str.trim().charAt(0)
}
const getearnings = () => {
  http.get('/order/earnings').then(res => {
    earningsdata.value.today_earnings = res.data.today_earnings
    earningsdata.value.yesterday_earnings = res.data.yesterday_earnings
  })
}
onMounted(() => {
  getearnings()
})
</script>

<style lang="scss" scoped>
.app-header {
  width: 100%;
  height: 48px;
  min-height: 48px;
  padding: 0 16px;
  position: absolute;
  display: flex;
  align-items: center;

  // background-color: #fff;
}
.header {
  display: flex;
  justify-content: space-between;
  flex: 1;
}
.avatar {
  width: 32px;
  height: 32px;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 20px;
  font-weight: 600;
  color: #fff;
  cursor: pointer;

  background-image: url('@/assets/menu/touxiang.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

.popover_user_content {
  position: relative;
  display: flex;
}
.popover_user_bg {
  width: 100%;
  height: 80px;
  background-image: url('@/assets/home/bg-user.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: absolute;
  z-index: 1;
}
.popover_user_list {
  z-index: 2;
  width: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;

  .user_popover_user {
    .touxiang {
      margin-top: 32px;
      display: flex;
      justify-content: center;
    }
    .user_name {
      margin-top: 12px;
      font-family: AlibabaPuHuiTi_2_85_;
      font-size: 16px;
      font-weight: bold;
      color: #000;
      text-align: center;
    }
    .login_out {
      margin-top: 8px;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100px;
      height: 28px;
      background-color: #f3f5fd;
      cursor: pointer;
      font-family: AlibabaPuHuiTi_2_55_;
      font-size: 12px;
      color: #000;
    }
  }

  .user_popover_detail {
    margin-top: 16px;
    width: 300px;
    height: 92px;
    background-color: #fef6ea;
    display: flex;

    .balance {
      width: 150px;
      display: flex;
      flex-direction: column;
      padding-left: 12px;
      padding-top: 16px;

      .text1 {
        font-family: AlibabaPuHuiTi_2_65_;
        font-size: 12px;
        color: #666;
      }

      .text2 {
        // font-family: DINAlternate;
        font-size: 16px;
        font-weight: bold;
        color: #000;
        margin-top: 4px;
      }
    }
    .profit_loss {
      width: 150px;
      display: flex;
      flex-direction: column;
      padding-left: 12px;
      padding-top: 16px;

      .text1 {
        font-family: AlibabaPuHuiTi_2_65_;
        font-size: 12px;
        color: #666;
      }

      .text2 {
        // font-family: DINAlternate;
        font-size: 16px;
        font-weight: bold;
        color: #1cc535;
        margin-top: 4px;
      }
      .text3 {
        margin-top: 4px;
        font-family: AlibabaPuHuiTi_2_65_;
        font-size: 12px;
        color: #666;
      }
    }
  }

  .user_popover_buttons {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    padding: 0 16px;

    .user_popover_buttons_item {
      display: flex;
      align-items: center;
      font-family: AlibabaPuHuiTi_2_65_;
      font-size: 14px;
      color: #000;
      margin: 18px 0;
      cursor: pointer;
    }
  }
}
</style>

<style>
.popover_user {
  padding: 0 !important;
  box-shadow: 0 2px 8px 0 rgba(0, 0, 0, 0.2) !important;
}
.popover_user .el-popper__arrow::before {
  width: 0;
  height: 0;
}
</style>